import { Button, Form, Input } from 'antd';
import style from './login.module.less';
import storage from '@/utils/storage';
import api from '@/api';
import { Login } from '@/type/api'
export default function LoginFun() {

    const [form] = Form.useForm();
    const onFinish = async (values: Login.params) => {
        // const data = await api.login(values);
        // console.log(data);
        // storage.set('token', data.token);
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };

    type FieldType = {
        username?: string;
        password?: string;
    };

    const fillBtn = () => {
        form.setFieldsValue({
            username: 'JackMa',
            password: "123456"
        });
    }

    return (
        <>
            <div className={style.login_wrap}>
                <div className={style.login_content}>
                    <div className="title">系统登录</div>
                    <Form
                        form={form}
                        name="basic"
                        onFinish={onFinish}
                        onFinishFailed={onFinishFailed}
                        autoComplete="off"
                    >
                        <Form.Item<FieldType>
                            name="username"
                            rules={[{ required: true, message: '请输入用户名' }]}
                        >
                            <Input />
                        </Form.Item>

                        <Form.Item<FieldType>
                            name="password"
                            rules={[{ required: true, message: '请输入密码!' }]}
                        >
                            <Input.Password />
                        </Form.Item>

                        <Form.Item>
                            {/* block 适应父级的宽度 */}
                            <Button block type="primary" htmlType="submit">提交</Button>
                            <Button type="primary" onClick={fillBtn} style={{ marginTop: '10px' }}>填充</Button>
                        </Form.Item>
                    </Form>
                </div>
            </div>
        </>
    )
}


